(function(angular) {
	'use strict';
	angular.module("fs.waf").factory("piUploadService", piUploadService )
	.filter("loadStatus", [ '$filter', '$locale', 'piUploadService', function($filter, $locale, piUploadService) {
		return function(loadStatus, pattern) {
			return $filter('translate')(piUploadService.loadStatusFilter(loadStatus, pattern));
		};
	} ]).
	filter("piTypeFilter", [ '$filter', '$locale', '$translate','piUploadService', function($filter, $locale, $translate, piUploadService) {
		return function(optionValue, pattern) {
			return $filter('translate')(piUploadService.piTypeFilter(optionValue, pattern));
		};
	} ])
	.filter("piStatus", [ '$filter', '$locale', 'piUploadService', function($filter, $locale, piUploadService) {
		return function(piStatus, pattern) {
			return $filter('translate')(piUploadService.piStatusFilter(piStatus, pattern));
		};
	} ]);
	piUploadService.$inject = [ '$q', 'loggerFactory', 'commonService', 'ajaxServiceFactory', 'modalService', 'gridService', '$filter'];
	function piUploadService($q, loggerFactory, commonService, ajaxServiceFactory, modalService, gridService, $filter) {
		var log = loggerFactory.getLogger("piUploadService");
	
		function loadStatusFilter(optionValue) {
			var options = getLoadStatus();
			var optionLabel = '';
			if(options) {
				angular.forEach(options.data, function(obj, index) {
					if(optionValue == obj.value) {
						optionLabel = obj.label;
					}
				});
			}
			return optionLabel;
		}
		
		function piStatusFilter(optionValue) {
			var options = getTxnStatus();
			var optionLabel = '';
			if(options) {
				angular.forEach(options.data, function(obj, index) {
					if(optionValue == obj.value) {
						optionLabel = obj.label;
					}
				});
			}
			return optionLabel;
		}
		
		function piTypeFilter(optionValue) {
			var options = getPiType();
			var optionLabel = '';
			if(options) {
				angular.forEach(options.data, function(obj, index) {
					if(optionValue == obj.value) {
						optionLabel = obj.label;
					}
				});
			}
			return optionLabel;
		}
		
		function getLoadStatus() {
			var options = {
					"data" : [ {
						"label" : "",
						"value" : ""
					},{
						"label" : "label.loadstatus.c",
						"value" : "C"
					},{
						"label" : "label.loadstatus.w",
						"value" : "W"    
					}, {
						"label" : "label.loadstatus.e",
						"value" : "E"    
					}, {
						"label" : "label.loadstatus.i",
						"value" : "I"    
					},{
						"label" : "label.loadstatus.j",
						"value" : "J"    
					}, {
						"label" : "label.loadstatus.t",
						"value" : "T"    
					}, {
						"label" : "label.loadstatus.r",
						"value" : "R"    
					}, {
						"label" : "label.loadstatus.x",
						"value" : "X"    
					}, {
						"label" : "label.txnstatus.l",
						"value" : "L"    
					}, {
						"label" : "label.txnstatus.m",
						"value" : "M"    
					}]
				};
			return options;
		}
		
		function getTxnStatus() {
			var options = {
				"data" : [ {
					"label" : "",
					"value" : ""
				},{
					"label" : "label.txnstatus.c",
					"value" : "C"
				}, {
					"label" : "label.txnstatus.w",
					"value" : "W"    
				}, {
					"label" : "label.txnstatus.l",
					"value" : "L"    
				}, {
					"label" : "label.txnstatus.j",
					"value" : "J"    
				}, {
					"label" : "label.txnstatus.z",
					"value" : "Z"    
				}, {
					"label" : "label.txnstatus.f",
					"value" : "F"    
				}, {
					"label" : "label.txnstatus.r",
					"value" : "R"    
				}, {
					"label" : "label.txnstatus.x",
					"value" : "X"    
				}, {
					"label" : "label.txnstatus.p",
					"value" : "P"    
				}, {
					"label" : "label.txnstatus.m",
					"value" : "M"    
				}, {
					"label" : "label.loadstatus.e",
					"value" : "E"    
				}]
			};
			return options;
		}
		function getPiType() {
			var options = {
				"data" : [ {
					"label" : "",
					"value" : ""
				},{
					"label" : "Invoice",
					"value" : "I"
				},{
					"label" : "PI",
					"value" : "P"
				},{
					"label" : "Credit Memo",
					"value" : "C"    
				}]
			};
			return options;
		}
		

		function getAttachmentList(dataType, piLoadId, isView) {
			var params = {
				'srcTxnType' : dataType,
				'srcTxnRef' : $filter('encode')(piLoadId),
				'isViewPage' : isView,
				'storeTempTableFlag' : false
			};
			commonService.getAttachmentList(params);
		}
		
		return {
			loadStatusFilter : loadStatusFilter,
			piStatusFilter : piStatusFilter,
			piTypeFilter : piTypeFilter,
			getAttachmentList : getAttachmentList
		};
	}
})(angular);